package com.lunwen.lunwen.api;

import com.lunwen.lunwen.bean.Result;
import com.lunwen.lunwen.bean.Task;
import com.lunwen.lunwen.services.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Task)表控制层
 *
 * @author makejava
 * @since 2020-08-14 09:31:36
 */
@RestController
@RequestMapping("task")
public class TaskController {

    /**
     * 服务对象
     */
    @Autowired
    private TaskService taskService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOneby")
    public Result selectOneby(Integer id) {
        Result re = new Result();
        re.setCode("");
        re.setData(this.taskService.queryById(id));
        return re;
    }


    /**
     * 增加一条数据
     *
     * @param
     * @return 单条数据
     */
    @RequestMapping(value = "Taskadd", method = RequestMethod.POST, consumes = "application/json")
    public Result Taskadd(@RequestBody Task task) {
        Result re = new Result();
        this.taskService.insert(task);
        return re;
    }

    /**
     * 列出所有数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("listall")
    public Result listall(Integer id) {
        Result re = new Result();
        re.setCode("");
        re.setData(this.taskService.queryAllByLimit(0, 100));
        return re;
    }

}